package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 程序启动后,要求用户输入标题和正文,然后将数据保存到article表中
 */
public class Test3 {
    public static void main(String[] args) {
        Article article = InputUtil.getInputObject(new Article(),"请输入文章标题和正文");
        try (
                Connection connection = DBUtil.getConnection();
        ) {
            String  spl = "INSERE INTO article(title,content) " +
                          "VALUES(?,?)";
            PreparedStatement ps = connection.prepareStatement(spl);
            ps.setString(1,article.getContent());
            ps.setString(2,article.getTitle());
            int num = ps.executeUpdate();
            if(num>0){
                System.out.println("发表文章成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
